//
//  LJMRankArr_TableViewCell.m
//  wind
//
//  Created by 李金明 on 16/1/11.
//  Copyright © 2016年 李金明. All rights reserved.
//

#import "LJMRankArr_TableViewCell.h"
#import "LJMRink_Model.h"
//歌手的网址
#define SONERURL @"http://v1.ard.tj.itlily.com/ttpod?a=getnewttpod&id=46&app=ttpod&v=v8.1.3.2015112716&user_id=0&mid=iPhone4S&f=f320&s=s310&imsi=&hid=&splus=7.0.4&active=1&net=2&openudid=1389d9dc18cb741587d90a5aead8646421f95dc0&idfa=C9BC818C-A0F5-4F04-8F8D-841910E08DF7&utdid=VmGiKEXHDQ0DAIL2FOnFFzxV&alf=201200&bundle_id=com.ttpod.music&latitude=&longtitude="
//FM的网址
#define FMURL @"http://fm.api.ttpod.com/radiolist?utdid=UyKT11zHlGYBACzJ7%2FDxmdxJ&image_type=240_200"

//歌单网址
#define SONGURL @"http://search.dongting.com/songlist/search?q=tag:最热&page=1&size=10&app=ttpod&v=v8.1.3.2015112716&user_id=0&mid=iPhone4S&f=f320&s=s310&imsi=&hid=&splus=7.0.4&active=1&net=2&openudid=1389d9dc18cb741587d90a5aead8646421f95dc0&idfa=C9BC818C-A0F5-4F04-8F8D-841910E08DF7&utdid=VmGiKEXHDQ0DAIL2FOnFFzxV&alf=201200&bundle_id=com.ttpod.music&latitude=&longtitude="
//榜单的网址
#define RANKURL @"http://api.songlist.ttpod.com/channels/bhb/children?app=ttpod&v=v8.1.3.2015112716&user_id=0&mid=iPhone4S&f=f320&s=s310&imsi=&hid=&splus=7.0.4&active=1&net=2&openudid=1389d9dc18cb741587d90a5aead8646421f95dc0&idfa=C9BC818C-A0F5-4F04-8F8D-841910E08DF7&utdid=VmGiKEXHDQ0DAIL2FOnFFzxV&alf=201200&bundle_id=com.ttpod.music&latitude=&longtitude="


#define IMAGEWIDETH 25//图片的宽度
#define IMAGESIDE 40//图片与前后的间隔
#define IMAGETOP 10//图片与头之间的距离
#define IMAGEHEIGHT 30 // 图片的高度
#define LABELWIDETH 55 // label 的宽度
#define GAD 5//图片与label 相差5个
@interface LJMRankArr_TableViewCell ()
@property (nonatomic, retain) UIButton *rankBut;
@property (nonatomic, retain) UIImageView *rankImageV;
@property (nonatomic, retain) UILabel *rankLab;

@property (nonatomic, retain) UIButton *linstenBut;
@property (nonatomic, retain) UIImageView *listenImageV;
@property (nonatomic, retain) UILabel *listenLab;

@property (nonatomic, retain) UIButton *FMBut;
@property (nonatomic, retain) UIImageView *FMImageV;
@property (nonatomic, retain) UILabel *FMLab;

@property (nonatomic, retain) UIButton *sonerBut;
@property (nonatomic, retain) UIImageView *sonerImageV;
@property (nonatomic, retain) UILabel *sonerLab;

@property (nonatomic, retain) NSMutableArray *labArr;
@property (nonatomic, retain) NSMutableArray *imageArr;
@property (nonatomic, retain) NSMutableArray *butArr;

@end

@implementation LJMRankArr_TableViewCell


- (void)dealloc
{
    self.delegate = nil;
    [_labArr release];
    [_imageArr release];
    [_butArr release];
    [_rankBut release];
    [_rankImageV release];
    [_rankLab release];
    [_linstenBut release];
    [_listenImageV release];
    [_listenLab release];
    [_FMBut release];
    [_FMImageV release];
    [_FMLab release];
    [_sonerBut release];
    [_sonerImageV release];
    [_sonerLab release];
    [_dataArr release];
    [super dealloc];
}
#pragma 重写set方法
- (void)setDataArr:(NSMutableArray *)dataArr
{
    if (_dataArr != dataArr) {
        [_dataArr release];
        _dataArr = [dataArr retain];
    }
    if (0 != dataArr.count) {
        

LJMRink_Model *rankmodel = [dataArr objectAtIndex:0];
    [self.rankImageV sd_setImageWithURL:[NSURL URLWithString:rankmodel.picUrl] placeholderImage:nil];
    self.rankLab.text = rankmodel.name;
    
  LJMRink_Model *listenModel = [dataArr objectAtIndex:1];
    [self.listenImageV sd_setImageWithURL:[NSURL URLWithString:listenModel.picUrl] placeholderImage:nil];
    self.listenLab.text = listenModel.name;
    LJMRink_Model *FMmodel = [dataArr objectAtIndex:2];
    [self.FMImageV sd_setImageWithURL:[NSURL URLWithString:FMmodel.picUrl] placeholderImage:nil];
    self.FMLab.text = FMmodel.name;
    LJMRink_Model *sonerModel = [dataArr objectAtIndex:3];
    [self.sonerImageV sd_setImageWithURL:[NSURL URLWithString:sonerModel.picUrl] placeholderImage:nil];
    self.sonerLab.text = sonerModel.name;
    
        }

}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatView];
    }
    return self;
}
- (void)creatView
{
        self.backgroundColor = [UIColor whiteColor];
    self.labArr = @[].mutableCopy;
    self.imageArr = @[].mutableCopy;
    self.butArr = @[].mutableCopy;
    //rank
    self.rankBut = [UIButton buttonWithType:UIButtonTypeCustom];
    self.rankBut.backgroundColor = [UIColor clearColor];
    [self.rankBut addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.rankBut];
    [self.butArr addObject:self.rankBut];
    
    
    self.rankImageV = [[UIImageView alloc] init];
    self.rankImageV.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.rankImageV];
    [self.imageArr addObject:self.rankImageV];
    [_rankImageV release];
    
    self.rankLab = [[UILabel alloc] init];
    self.rankLab.font = [UIFont systemFontOfSize:16];
    self.rankLab.textAlignment = NSTextAlignmentCenter;
    self.rankLab.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.rankLab];
    [self.labArr addObject:self.rankLab];
    [_rankLab release];
    
    //listen
    self.linstenBut = [UIButton buttonWithType:UIButtonTypeCustom];
    self.linstenBut.backgroundColor = [UIColor clearColor];
    [self.linstenBut addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.linstenBut];
    [self.butArr addObject:self.linstenBut];
    
    
    self.listenImageV = [[UIImageView alloc] init];
    self.listenImageV.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.listenImageV];
    [self.imageArr addObject:self.listenImageV];
    [_listenImageV release];
    
    self.listenLab = [[UILabel alloc] init];
    self.listenLab.font = [UIFont systemFontOfSize:16];
    self.listenLab.textColor = [UIColor grayColor];
    self.listenLab.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.listenLab];
    [self.labArr addObject:self.listenLab];
    [_listenLab release];
    
    //FM
    self.FMBut = [UIButton buttonWithType:UIButtonTypeCustom];
    self.FMBut.backgroundColor = [UIColor clearColor];
    [self.FMBut addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.FMBut];
    [self.butArr addObject:self.FMBut];
    
    self.FMImageV = [[UIImageView alloc] init];
    self.FMImageV.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.FMImageV];
    [self.imageArr addObject:self.FMImageV];
    [_FMImageV release];
    
    self.FMLab = [[UILabel alloc] init];
    self.FMLab.font = [UIFont systemFontOfSize:16];
    self.FMLab.textColor = [UIColor grayColor];
    self.FMLab.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.FMLab];
    [self.labArr addObject:self.FMLab];
    [_FMLab release];
    
    //soner
    self.sonerBut = [UIButton buttonWithType:UIButtonTypeCustom];
    self.sonerBut.backgroundColor = [UIColor clearColor];
    [self.sonerBut addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.sonerBut];
    [self.butArr addObject:self.constraints];
    
    self.sonerImageV = [[UIImageView alloc] init];
    self.sonerImageV.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.sonerImageV];
    [self.imageArr addObject:self.sonerImageV];
    [_sonerImageV release];
    
    self.sonerLab = [[UILabel alloc] init];
    self.sonerLab.font = [UIFont systemFontOfSize:16];
    self.sonerLab.textAlignment = NSTextAlignmentCenter;
    self.sonerLab.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.sonerLab];
    [self.labArr addObject:self.sonerLab];
    [_sonerLab release];
    
    
    

}
- (void)layoutSubviews
{
    [self.imageArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:IMAGEWIDETH leadSpacing:IMAGESIDE tailSpacing:IMAGESIDE];
    [self.imageArr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@IMAGETOP);
        make.height.equalTo(@IMAGEHEIGHT);
    }];
    [self.rankLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.rankImageV);
        make.width.mas_equalTo(@LABELWIDETH);
        make.top.mas_equalTo(self.rankImageV.mas_bottom).offset(GAD);
        make.height.mas_equalTo(@IMAGEHEIGHT);
    }];
    [self.listenLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.listenImageV);
        make.width.mas_equalTo(@LABELWIDETH);
        make.top.mas_equalTo(self.listenImageV.mas_bottom).offset(GAD);
        make.height.mas_equalTo(@IMAGEHEIGHT);
    }];
    [self.FMLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.FMImageV);
        make.width.mas_equalTo(@LABELWIDETH);
        make.top.mas_equalTo(self.FMImageV.mas_bottom).offset(GAD);
        make.height.mas_equalTo(@IMAGEHEIGHT);
    }];
    [self.sonerLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.sonerImageV);
        make.width.mas_equalTo(@LABELWIDETH);
        make.top.mas_equalTo(self.sonerImageV.mas_bottom).offset(GAD);
        make.height.mas_equalTo(@IMAGEHEIGHT);
    }];
    [self.rankBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.rankImageV);
        make.width.mas_equalTo(@LABELWIDETH);
        make.top.mas_equalTo(self.rankImageV.mas_top);
        make.bottom.mas_equalTo(self.rankLab.mas_bottom);
    }];
    [self.linstenBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.listenImageV);
        make.width.mas_equalTo(@LABELWIDETH);
        make.top.mas_equalTo(self.listenImageV.mas_top);
        make.bottom.mas_equalTo(self.listenLab.mas_bottom);
    }];
    [self.FMBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.FMImageV);
        make.width.mas_equalTo(@LABELWIDETH);
        make.top.mas_equalTo(self.FMImageV.mas_top);
        make.bottom.mas_equalTo(self.FMLab.mas_bottom);
    }];
    [self.sonerBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.sonerImageV);
        make.width.mas_equalTo(@LABELWIDETH);
        make.top.mas_equalTo(self.sonerImageV.mas_top);
        make.bottom.mas_equalTo(self.sonerLab.mas_bottom);
    }];

}
#pragma button的方法
- (void)buttonAction:(UIButton *)sender
{
    if (sender == self.rankBut) {
        NSString *str = RANKURL;
        [self.delegate changeVCUrl:str type:@"RANK"];
    }
    if (sender == self.linstenBut) {
        NSLog(@"linsten");
        NSString *str = SONGURL;
        [self.delegate changeVCUrl:str type:@"SONG"];
        
    }
    if (sender == self.FMBut) {
        NSLog(@"FM");
        NSString *str = FMURL;
        [self.delegate changeVCUrl:str type:@"FM"];
        
    }
    if (sender == self.sonerBut) {
        NSString *str = SONERURL;
        [self.delegate changeVCUrl:str type:@"Rank_soner"];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
